/**
 * Created by Administrator on 2017/3/2 0002.
 */
var Game={
    create:function () {
        var game={};
        var con=new PIXI.DisplayObjectContainer();
        con.interactive=true;
        // for(var i=0;i<5;i++)
        // {
        //     var page=Page1.create();
        //     con.addChild(page.ui);
        //     page.ui.y=i*pixiStageH;
        // }


        //

        // var pageInfo=PageInfo.create();
        // pageInfo.In();
        // con.addChild(pageInfo.ui);
        //红酒
        var  text_des0=[
            '它很有品味',
            '它时间越久越好',
            '它有绅士气息',
            '它气味芬芳',
            '法国.波尔多'
        ];
        //按摩床
        var  text_des1=[
            '它会让你放松',
            '它很舒适',
            '它能使你身心健康',
            '它很软',
            '它能让你忘了一天的疲惫'
        ]
        //马的画
        var text_des2=[
            '它是一个动物',
            '它有四条腿',
            '它有棕色的毛发',
            '它是一个艺术品'
        ]
        //灯
        var text_des3=[
            '它是一个家具',
            '它能发光',
            '它要用电'
        ]
        //餐具
        var text_des4=[
            '它是每天都要用',
            '它用好都要清洗',
            '它易碎'
        ]
        //壁灯
        var text_des5=[
            '它在墙壁上',
            '它能发光',
            '它要用电'
        ];
        //婚纱
        var text_des6=[
            '它很美',
            '它会让你感到幸福',
            '它会让你变美',
            '非常昂贵',
            '它很隆重'
        ];
        //灯
        var text_des7=[
            '它给你的阅读带来方便',
            '他会让你感到光明',
            '它在卧室必不可少',
            '它在卧室必不可少',
            '它可以很有设计感'
        ];
        //吧台椅子
        var text_des8=[
            '它是家具',
            '它可以很有设计感',
            '它是木制的',
            '他是不可缺少的'
        ];
        //酒杯
        var text_des9=[
            '他是容器',
            '玻璃制品',
            '它非常精致',
            '他可以很有设计感',
            '易碎'
        ];
        var score=0;
        var arr_text=[];
        arr_text.push(text_des0,text_des1,text_des2,text_des3,text_des4,text_des5,text_des6,text_des7,text_des8,text_des9);
        var scene1_ans,scene2_ans,scene3_ans,scene4_ans,scene5_ans;
        if(Math.random()>0.5)
        {
            scene1_ans=2;
        }
        else{
            scene1_ans=3;
        }
        if(Math.random()>0.5)
        {
            scene2_ans=4;
        }
        else{
            scene2_ans=5;
        }
        if(Math.random()>0.5)
        {
            scene3_ans=6;
        }
        else{
            scene3_ans=7;
        }
        if(Math.random()>0.5)
        {
            scene4_ans=0;
        }
        else{
            scene4_ans=1;
        }
        if(Math.random()>0.5)
        {
            scene5_ans=8;
        }
        else{
            scene5_ans=9;
        }
        var arr_ans=[];
        arr_ans.push(scene1_ans,scene2_ans,scene3_ans,scene4_ans,scene5_ans);
        console.log('answer:::::::::::::',arr_ans);

        var sp_heartPlane=new PIXI.Sprite(resource['assets/images/heartPlane.png'].texture);
        sp_heartPlane.anchor.set(0.5);
        sp_heartPlane.x=120;
        sp_heartPlane.y=47+90;
        con.addChild(sp_heartPlane);

        var arr_heart=[];
        for(var i=0;i<5;i++)
        {
            var heart=new PIXI.Sprite(resource['assets/images/heartRed.png'].texture);
            heart.anchor.set(0.5);
            heart.x=-96+48*i;
            // heart.y=47;

            arr_heart.push(heart);
        }



        var arr_p0=[
            {x:2480,y:160,ans:5,des:scene2_ans,idx:2},
            {x:2083,y:476,ans:-1,des:scene2_ans,idx:2},
            {x:2081,y:574,ans:4,des:scene2_ans,idx:2},
            {x:1872,y:305,ans:-1,des:scene2_ans,idx:2},
            {x:1739,y:459,ans:-1,des:scene2_ans,idx:2},
            {x:1393,y:318,ans:3,des:scene1_ans,idx:1},
            {x:1235,y:741,ans:-1,des:scene1_ans,idx:1},
            {x:963,y:225,ans:2,des:scene1_ans,idx:1},
            {x:865,y:464,ans:-1,des:scene1_ans,idx:1},
            {x:502,y:318,ans:3,des:scene1_ans,idx:1}
        ];

        var arr_p1=[
            {x:2412,y:70,ans:-1,des:scene3_ans,idx:3},
            {x:2366,y:90,ans:-1,des:scene3_ans,idx:3},
            {x:2238,y:140,ans:-1,des:scene3_ans,idx:3},
            {x:2100,y:312,ans:-1,des:scene3_ans,idx:3},
            {x:1720,y:420,ans:-1,des:scene3_ans,idx:3},
            {x:1401,y:392,ans:6,des:scene3_ans,idx:3},
            {x:880,y:198,ans:7,des:scene3_ans,idx:3},
            {x:673,y:231,ans:-1,des:scene3_ans,idx:3},
            {x:534,y:464,ans:-1,des:scene3_ans,idx:3},
            {x:159,y:444,ans:-1,des:scene3_ans,idx:3},
            {x:105,y:457,ans:-1,des:scene3_ans,idx:3},
            {x:200,y:167,ans:7,des:scene3_ans,idx:3}
            ];
        var arr_p2=[
            {x:3496,y:406,ans:-1,des:scene4_ans,idx:4},
            {x:3364,y:520,ans:-1,des:scene4_ans,idx:4},
            {x:3296,y:475,ans:1,des:scene4_ans,idx:4},
            {x:3202,y:339,ans:-1,des:scene4_ans,idx:4},
            {x:3104,y:523,ans:-1,des:scene4_ans,idx:4},
            {x:3140,y:585,ans:-1,des:scene4_ans,idx:4},
            {x:2941,y:404,ans:-1,des:scene4_ans,idx:4},
            {x:2149,y:577,ans:-1,des:scene4_ans,idx:4},
            {x:1980,y:404,ans:0,des:scene4_ans,idx:4},
            {x:1326,y:304,ans:-1,des:scene5_ans,idx:5},
            {x:1005,y:418,ans:-1,des:scene5_ans,idx:5},
            {x:877,y:645,ans:8,des:scene5_ans,idx:5},
            {x:747,y:478,ans:9,des:scene5_ans,idx:5},
            {x:228,y:397,ans:-1,des:scene5_ans,idx:5}

        ];
        var  arr_place=[];
        var  currentScene;
        arr_place.push(arr_p0,arr_p1,arr_p2);

        var scene0=Scene.create(0,arr_place[0],arr_text);
        scene0.ui.interactive=true;
        var scene1=Scene.create(1,arr_place[1],arr_text);
        scene1.ui.interactive=true;
        var scene2=Scene.create(2,arr_place[2],arr_text);
        scene2.ui.interactive=true;


        currentScene=scene0.ui;
        con.addChild(currentScene);
        con.addChild(sp_heartPlane);

        var p0_bt0=new PIXI.Sprite(resource['assets/images/g0_bt0.png'].texture);
        p0_bt0.interactive=true;
        p0_bt0.anchor.set(0.5);
        p0_bt0.x=1881;
        p0_bt0.y=225;
        scene0.ui.addChild(p0_bt0);
        p0_bt0.on('pointerdown',function (e) {
            e.data.originalEvent.preventDefault();
            e.data.originalEvent.stopImmediatePropagation();
            if(currentScene.parent)
            {
                currentScene.parent.removeChild(currentScene);
            }
            currentScene=scene2.ui;
            currentScene.x=0;
            con.addChild(currentScene);
            con.addChild(sp_heartPlane);
        });
        new TWEEN.Tween({y:225,alpha:0.7})
            .to({y:225+15,alpha:1})
            .onUpdate(function () {
                p0_bt0.y=this.y;
                p0_bt0.alpha=this.alpha;
            })
            .repeat(Infinity)
            .yoyo(true)
            .easing(TWEEN.Easing.Cubic.InOut)
            .start();

        var p0_bt1=new PIXI.Sprite(resource['assets/images/g0_bt1.png'].texture);
        p0_bt1.interactive=true;
        p0_bt1.anchor.set(0.5);
        p0_bt1.x=2516;
        p0_bt1.y=326;
        scene0.ui.addChild(p0_bt1);
        p0_bt1.on('pointerdown',function (e) {
            e.data.originalEvent.preventDefault();
            e.data.originalEvent.stopImmediatePropagation();
            if(currentScene.parent)
            {
                currentScene.parent.removeChild(currentScene);
            }
            currentScene=scene1.ui;
            currentScene.x=0;
            con.addChild(currentScene);
            con.addChild(sp_heartPlane);
        });
        new TWEEN.Tween({x:2516-15,alpha:0.7})
            .to({x:2516,alpha:1})
            .onUpdate(function () {
                p0_bt1.x=this.x;
                p0_bt1.alpha=this.alpha;
            })
            .repeat(Infinity)
            .yoyo(true)
            .easing(TWEEN.Easing.Cubic.InOut)
            .start();

        var p1_bt0=new PIXI.Sprite(resource['assets/images/g1_bt0.png'].texture);
        p1_bt0.interactive=true;
        p1_bt0.anchor.set(0.5);
        p1_bt0.x=83;
        p1_bt0.y=598;
        scene1.ui.addChild(p1_bt0);
        p1_bt0.on('pointerdown',function (e) {
            e.data.originalEvent.preventDefault();
            e.data.originalEvent.stopImmediatePropagation();
            if(currentScene.parent)
            {
                currentScene.parent.removeChild(currentScene);
            }
            currentScene=scene0.ui;
            // currentScene.x=2590-1136;
            con.addChild(currentScene);
            con.addChild(sp_heartPlane);
        });
        new TWEEN.Tween({x:83+15,alpha:0.7})
            .to({x:83,alpha:1})
            .onUpdate(function () {
                p1_bt0.x=this.x;
                p1_bt0.alpha=this.alpha;
            })
            .repeat(Infinity)
            .yoyo(true)
            .easing(TWEEN.Easing.Cubic.InOut)
            .start();

        var p2_bt0=new PIXI.Sprite(resource['assets/images/g1_bt0.png'].texture);
        p2_bt0.interactive=true;
        p2_bt0.anchor.set(0.5);
        p2_bt0.x=83;
        p2_bt0.y=598;
        scene2.ui.addChild(p2_bt0);
        p2_bt0.on('pointerdown',function (e) {
            e.data.originalEvent.preventDefault();
            e.data.originalEvent.stopImmediatePropagation();
            if(currentScene.parent)
            {
                currentScene.parent.removeChild(currentScene);
            }
            currentScene=scene0.ui;
            // currentScene.x=2590-1136;
            con.addChild(currentScene);
            con.addChild(sp_heartPlane);
        });
        new TWEEN.Tween({x:83+15,alpha:0.7})
            .to({x:83,alpha:1})
            .onUpdate(function () {
                p2_bt0.x=this.x;
                p2_bt0.alpha=this.alpha;
            })
            .repeat(Infinity)
            .yoyo(true)
            .easing(TWEEN.Easing.Cubic.InOut)
            .start();

        var pageText=PageText.create();
        var arr_sceneIdxClicked=[];

        game.ui=con;


        document.addEventListener('Game_ItemDown',function (e) {
            if(!pageText.ui.parent)
            {
                for(var j=0;j<arr_sceneIdxClicked.length;j++)
                {
                    if(e.detail[2]==arr_sceneIdxClicked[j])
                    {
                        pageText.Bala();


                        // return;
                    }
                }

                con.addChild(pageText.ui);

                var bool=false;
                for(var i=0;i<arr_ans.length;i++)
                {

                    console.log('arr_ans:::::::::',e.detail[1]);
                    if(e.detail[1]==arr_ans[i])
                    {
                        arr_ans.splice(i,1);
                        bool=true;
                        // console.log('answerIn',e.detail[2]);
                        arr_sceneIdxClicked.push(e.detail[2]);
                        score++;
                        sp_heartPlane.addChild(arr_heart[score-1]);
                        con.addChild(sp_heartPlane);
                        break;
                    }
                }
                if(!bool)
                {
                    pageText.In(e.detail[0]);
                }
                else
                {
                    pageText.InRight(e.detail[2],score);
                }
                if(score==5)
                {

                }

            }

        });
        document.addEventListener('Game_TextOut',function (e) {
            // currentScene.interactive=true;
        });
        
        
        return game;
    }

}